package javaweb.sevice.impl;

import javaweb.mapper.EmpMapper;
import javaweb.mapper.StudentMapper;
import javaweb.pojo.ClazzOption;
import javaweb.pojo.JobOption;
import javaweb.sevice.ReportDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;

@Service
public class ReportDataServiceImpl implements ReportDataService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    /*
    * 获取员工职位报表信息
    * */
    @Override
    public JobOption getEmpJobData() {
        //1.调用Mapper接口
        List<Map<String, Object>> list = empMapper.countEmpJobDta();

        //2.封装JobOption对象
        /*
        * map匿名内部类写法
        * */
        List<Object> jobList = list.stream().map(new Function<Map<String, Object>, Object>() {
            @Override
            public Object apply(Map<String, Object> map) {
                return map.get("pos");
            }
        }).toList();
        /*
        * Lambda表达式写法
        * */
        List<Object> dataList = list.stream().map(map -> map.get("num")).toList();

        return new JobOption(jobList, dataList);
    }

    /*
    * 获取员工性别报表
    * */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    /*
    * 获取学员班级人数报表
    * */
    @Override
    public ClazzOption getStudentCountData() {
        //调用Mapper接口
        List<Map<String, Object>> list = studentMapper.countStudentByClazz();

        //封装数据
        List<Object> clazzList = list.stream().map(map -> map.get("name")).toList();
        List<Object> dataList = list.stream().map(map -> map.get("num")).toList();

        return new ClazzOption(clazzList, dataList);
    }

    @Override
    public List<Map<String, Object>> getStudentDegreeData(){
        return studentMapper.getStudentDegreeData();
    }
}
